$(document).ready(function () {
	
	//RECENTLY ORDERS
	setInterval(function() {
		getLastestItem();	
	}, 5000);
	
	function getLastestItem() {
		$.ajax({
			type: "POST",
			url: "ajax_lastest_item.php",
			dataType: "json",
			success: function(response)
			{	
				var exists = false;
				var limit = 5;
				if (response.id) {
					$("#latest-gigs ul li").each(function (index) {
						if ($(this).attr("id") == response.id) {
							exists = true;
						}
					});
					
				}
				
				if (!exists) {
					$("#latest-gigs ul").prepend(response.content);
		        	$("#latest-gigs ul li").eq(0).hide().show("blind", {percent: 100}, 600);
		        	if ($("#latest-gigs ul li").length > limit) {
		        		$("#latest-gigs ul li").eq(-1).hide("blind", {percent: 100}, 600);
		        	}
		        	setTimeout(function() {			        		
		        		if ($("#latest-gigs ul li").length > limit) {
		        			$("#latest-gigs ul li").eq(-1).remove();
		        		}
		        		$("#latest-gigs ul li").removeClass("last");
		        		$("#latest-gigs ul li").eq(-1).addClass("last");
		        	}, 500);
				}
			}
		});
	}
});